package br.com.pontoclass.primes;

import java.math.BigInteger;
import java.util.logging.Level;
import java.util.logging.Logger;

import br.com.pontoclass.patterns.PrimeNumberListener;
import br.com.pontoclass.primes.util.MathLogicUtil;


public class PrimesDifferencePrinterPrimeNumberListener implements PrimeNumberListener {
    
    private static final Logger LOGGER = Logger.getLogger(PrimesDifferencePrinterPrimeNumberListener.class.getName());
    private BigInteger last = new BigInteger("2");
    private String base;
    
    public PrimesDifferencePrinterPrimeNumberListener(String base) {
        this.base = base;
        
    }
    
    @Override
    public void onAddPrime(BigInteger prime) {
        prime = MathLogicUtil.convertFrom(new BigInteger(base), prime);
        String out;
        System.out.println(out=String.format("prime [%s] diff [%s]", prime, (prime.subtract(last).toString())));
        last = prime;
        LOGGER.log(Level.INFO, out);
    }
}